# Assignment 2, Q3 and Q4 (v1.0)
# You may modify this file for testing purposes, 
# but your final assignment2.rb must be able to run with the original main.rb.

load "utility.rb"
load "wgraph.rb"
load "assignment2.rb"

# load_graph reads from the CSV file and populates the graph in $g.
g = load_graph("data\\actorlinks1.csv")   # load_graph is found in utility.rb
p "----------------------------------------------------"

# Q3a
puts
p "Testing get_shortest_link_between_actors..."
startTime = Time.now # notice that the time for load_graph is not taken into consideration 

# the following lines of code will be replaced with many more calls on the submission server
p "get_SHORTEST_link_between_actors (Bobo Chan) and (Gillian Chung)"
actor_chain = get_shortest_link_between_actors(g, "Bobo Chan", "Gillian Chung")
# show time lapsed
execTime = Time.now - startTime
puts "Execution time #{execTime} seconds."

# check if your method returned a valid answer. A valid answer may not be the best answer.
p "returned :"
p get_display_string(actor_chain)
valid = check_valid_chain(g, actor_chain)  # check_valid_chain is found in utility.rb
p "valid chain? :" + valid.to_s
if (valid)
    p "number of hops :" + (actor_chain.size-1).to_s
end
p "----------------------------------------------------"

# Q3b
puts
p "Testing get_closest_link_between_actors..."
startTime = Time.now

# the following lines of code will be replaced with many more calls on the submission server
p "get_CLOSEST_link_between_actors (Kenix Kwok) and (Michael Lam)"
actor_chain = get_closest_link_between_actors(g, "Kenix Kwok", "Michael Lam")
# show time lapsed
execTime = Time.now - startTime
puts "Execution time #{execTime} seconds."

# check if your method returned a valid answer. A valid answer may not be the best answer.
p "returned :" + get_display_string(actor_chain)
valid = check_valid_chain(g, actor_chain)
p "valid chain? :" + valid.to_s
if (valid)
    p "total weight of edges :" + get_total_weight(g, actor_chain).to_s  # get_total_weight is found in utility.rb
end
p "----------------------------------------------------"

# Q4

puts
p "Testing get_largest_set_of_independent_actors..."
startTime = Time.now

# the method get_largest_set_of_independent_actors will only be called ONCE on the submission server for each test graph
p "get_largest_set_of_independent_actors"
actor_set = get_largest_set_of_independent_actors(g)
# show time lapsed
execTime = Time.now - startTime
puts "Execution time #{execTime} seconds."

# check if your method returned a valid answer. A valid answer may not be the best answer.
p "returned :" + get_display_string(actor_set)
valid = check_valid_independent_set(g, actor_set)  # check_valid_independent_set is found in utility.rb
p "valid independent set? :" + valid.to_s
if (valid)
    p "total number of actors :" + actor_set.size.to_s
end

# ---------------------------------------------------